//1.typeof的类型缩小

//2.平等的类型缩小

//3.instanceof
class Student{
  studying(){

  }
}

class Teacher{
  teaching(){

  }
}

function work(p:Student | Teacher){
  if(p instanceof Student){
    p.studying()
  }else{
    p.teaching()
  }
}
work(new Student())

//4.in
type Fish = {
  swimming:()=> void
}

type Dog = {
  running:()=> void
}

function walk(p:Fish | Dog){
  if('swimming' in p){
    p.swimming()
  }else{
    p.running()
  }
}

const fish:Fish ={
  swimming:()=>{
    console.log('swimming');
    
  }
}
walk(fish)
